<template>
  <div id="LineStatistics"></div>
</template>

<script>
import * as echarts from 'echarts/core'
import {
  TitleComponent,
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent
} from 'echarts/components'
import { LineChart } from 'echarts/charts'
import { UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'
export default {
  name: 'LineStatistics',
  data () {
    return {
      // 数据
      lineX: ['1号', '2号', '3号', '4号', '5号', '6号', '7号'],
      dataone: [200, 150, 146, 120, 140, 160, 50],
      datatwo: [150, 140, 130, 110, 150, 160, 20]
    }
  },
  created () {
    echarts.use([
      TitleComponent,
      ToolboxComponent,
      TooltipComponent,
      GridComponent,
      LegendComponent,
      LineChart,
      CanvasRenderer,
      UniversalTransition
    ])
  },
  mounted () {
    // 找到这个容器
    this.myChart = echarts.init(this.$el)
    const that = this
    // 配置项
    let option = {
      title: {
        text: '离线故障率'
      },
      // 提示框
      tooltip: {
        //触发类型
        trigger: 'axis',
        // 提示框的背景颜色
        backgroundColor: 'rgba(173, 198, 255, 0.50)',
        // 提示框边框厚度
        borderWidth: 0,
        // 提示款边框颜色
        borderColor: '#ccc',
        // 提示框字体颜色
        textStyle: {
          color: '#fff'
        },
        // 选中数据时x-y轴样式
        axisPointer: {
          type: 'cross',
          // 小方块
          label: {
            // 小方块背景颜色
            backgroundColor: '#6a7985'
            // backgroundColor: '#e10602'
            // 小方块字体颜色
            // color: '#e10602'
          }
        }
      },
      legend: {
        // data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
        //字体样式
        textStyle: {
          //   color: '#E0E0E0',
          color: '#1e1e1e',
          fontSize: 10
        },
        //图标形状
        icon: 'roundRect',
        orient: 'horizontal',
        itemWidth: 13,
        itemHeight: 3,
        right: '10%',
        top: 0
      },
      // 工具箱-下载
      toolbox: {
        feature: {
          saveAsImage: {}
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: [
        {
          // 单位
          name: 'dkjflk',
          type: 'category',
          boundaryGap: false,
          data: this.lineX,
          axisTick: {
            show: false
            // length:7
          },
          axisLine: {
            lineStyle: {
              color: 'rgba(32, 121, 160, 0.3)'
            }
          },
          axisLabel: {
            color: '#7AADFF ',
            margin: 10
          },
          nameTextStyle: {
            color: '#7AADFF ',
            fontSize: 8
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(255,255,255,0.08)'
            }
          }
        }
      ],
      yAxis: [
        {
          type: 'value',
          splitNumber: 3,
          axisLine: {
            show: true,
            lineStyle: {
              color: 'rgba(32, 121, 160, 0.3)'
            }
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            color: '#7AADFF ',
            margin: 10
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(32, 121, 160, 0.3)'
            }
          },
          splitArea: {
            areaStyle: {
              color: 'rgba(2, 29, 159, 0.7)'
            }
          }
        }
      ],
      series: [
        {
          name: '离线率',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          // 鼠标在图例上的效果
          emphasis: {
            // 选中这条数据，隐藏其他数据
            // focus: 'series'
          },
          data: this.dataone,
          // 折线变得圆滑
          smooth: true,
          // 把点去掉
          showSymbol: false,
          // 折线颜色
          lineStyle: {
            width: 3,
            color: '#32C5FF'
            // color: '#1e1e1e'
          },
          // 标头-颜色
          itemStyle: {
            color: '#32C5FF'
            // color: '#1e1e1e'
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: 'rgba(50, 197, 255, 0.4)'
              },
              {
                offset: 1,
                color: 'rgba(55, 167, 232, 0.4)'
              }
            ])
          }
        },
        {
          name: '故障率',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            // focus: 'series'
          },
          data: this.datatwo,
          // 折线变得圆滑
          smooth: true,
          // 把点去掉
          showSymbol: false,
          lineStyle: {
            width: 3,
            color: '#0368FF'
          },
          itemStyle: {
            color: '#0368FF'
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: 'rgba(50, 197, 255, 0.4)'
              },
              {
                offset: 1,
                color: 'rgba(55, 167, 232, 0.4)'
              }
            ])
          }
        }
      ]
    }
    // 渲染数据
    this.myChart.setOption(option)
  }
}
</script>

<style lang="scss" scoped>
#LineStatistics {
  width: 100%;
  height: 100%;
}
</style>
